<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="进货通知单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="recId">
              <a-input v-model="model.recId" placeholder="请输入进货通知单号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="进出货日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="recDate">
              <j-date placeholder="请选择进出货日期" v-model="model.recDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="进出货类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="recType">
              <a-input v-model="model.recType" placeholder="请输入进出货类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="供应商客户编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="custId">
              <a-input v-model="model.custId" placeholder="请输入供应商客户编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="供应商客户简称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shortName">
              <a-input v-model="model.shortName" placeholder="请输入供应商客户简称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="车号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="carno">
              <a-input v-model="model.carno" placeholder="请输入车号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="柜号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="arkno">
              <a-input v-model="model.arkno" placeholder="请输入柜号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="noteS">
              <a-input v-model="model.noteS" placeholder="请输入备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="物料partNo" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="partNo">
              <a-input v-model="model.partNo" placeholder="请输入物料partNo"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="英文名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="egName">
              <a-input v-model="model.egName" placeholder="请输入英文名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="英文规格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="egModel">
              <a-input v-model="model.egModel" placeholder="请输入英文规格"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="中文名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入中文名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="中午规格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standard">
              <a-input v-model="model.standard" placeholder="请输入中午规格"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="unit">
              <a-input v-model="model.unit" placeholder="请输入单位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="单价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="price">
              <a-input v-model="model.price" placeholder="请输入单价"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="进出货数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fmQty">
              <a-input v-model="model.fmQty" placeholder="请输入进出货数量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="国别代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tradeCoun">
              <a-input v-model="model.tradeCoun" placeholder="请输入国别代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="币制" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="curr">
              <a-input v-model="model.curr" placeholder="请输入币制"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="件数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="boxCount">
              <a-input v-model="model.boxCount" placeholder="请输入件数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="净重" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="boxNetW">
              <a-input v-model="model.boxNetW" placeholder="请输入净重"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="毛重" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="boxGrossW">
              <a-input v-model="model.boxGrossW" placeholder="请输入毛重"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="箱号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pkgNo">
              <a-input v-model="model.pkgNo" placeholder="请输入箱号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注(po或so)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="note">
              <a-input v-model="model.note" placeholder="请输入备注(po或so)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="退运的原产国代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="country2">
              <a-input v-model="model.country2" placeholder="请输入退运的原产国代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="手册编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="manualNo">
              <a-input v-model="model.manualNo" placeholder="请输入手册编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="海关备案" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="coalitionNo">
              <a-input v-model="model.coalitionNo" placeholder="请输入海关备案"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备用字段1" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="note1">
              <a-input v-model="model.note1" placeholder="请输入备用字段1"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备用字段2" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="note2">
              <a-input v-model="model.note2" placeholder="请输入备用字段2"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备用字段3" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="note3">
              <a-input v-model="model.note3" placeholder="请输入备用字段3"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备用字段4" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="note4">
              <a-input v-model="model.note4" placeholder="请输入备用字段4"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ChImportExportDocumentsForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/ch/chImportExportDocuments/add",
          edit: "/ch/chImportExportDocuments/edit",
          queryById: "/ch/chImportExportDocuments/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>